package ee.fj.util.assertion;

import java.util.regex.Pattern;


public class RegexpAssertion extends Assertion {
	private final Pattern pattern;

	public RegexpAssertion(Pattern pattern) {
		this(pattern, DEFAULT_CONDITION);
	}

	public RegexpAssertion(Pattern pattern, boolean reverse) {
		super(reverse);
		this.pattern = pattern;
	}

	public RegexpAssertion(String pattern) {
		this(pattern, DEFAULT_CONDITION);
	}

	public RegexpAssertion(String pattern, boolean reverse) {
		this(Pattern.compile(pattern), reverse);
	}

	@Override
	protected boolean satisfiesInner(Object value) {
		return value != null && pattern.matcher(value.toString()).matches();
	}

}
